package com.shareppy.normanhttp;

import org.apache.http.Header;
import org.apache.http.HttpResponse;

import android.content.Context;

public class HttpRequestTask extends AbstractHttpRequest {

	protected boolean useLoginSign = false;

	public HttpRequestTask(Context context) {
		super(context);
	}

	public HttpRequestTask(Context context, String service) {
		super(context, service);
	}

	public HttpRequestTask(Context context, String service, int activityId) {
		super(context, service, activityId, null);
	}

	public HttpRequestTask(Context context, String service, int activityId,
			String taskTitle) {
		super(context, service, activityId, taskTitle);
	}

	public void setUseLoginSign(boolean useLoginSign) {
		this.useLoginSign = useLoginSign;
	}

	@SuppressWarnings("unchecked")
	public HttpRequestTask getClone() {
		HttpRequestTask clone = new HttpRequestTask(getContext(), service);
		clone.setUseLoginSign(useLoginSign);
		clone.setActivityId(getActivityId());
		clone.setTaskTitle(taskTitle);
		return clone;
	}

	protected void addCustomParams(HttpRequestParams params) {
		if (HttpTaskConfig.getSecureParams() != null) {
			HttpTaskConfig.getSecureParams().addSecureParams(params,
					useLoginSign);
		}
	}

	protected void processResponse(HttpResponse response) {
		Header[] headers = response.getHeaders("stoken");
		if (headers != null && headers.length > 0) {
			HttpTaskConfig.secureToken = headers[0].getValue();
		}
	}

}